var GownFullHTMLTextareaAdapter = GownFullHTMLInputTextAdapter.extend({
	constructor: function(obj)
	{
		this.base(obj);
	},
	clone: function(obj)
	{
		return new GownFullHTMLTextareaAdapter(obj);
	},
/*
Yet Another way to get the selection (cursor) position of textarea of IE

This is a modification version of a comment written by Strifer in the following blog:

Modified by wonghang on 2008-01-04.

http://weblogs.asp.net/skillet/archive/2005/03/24/395838.aspx

As of 2008-01-04, the link to the user is dead (404 File Not Found)
*/
	yaIEGetSelectionStart: function()
	{
		var ta = this.obj;
		var range = document.selection.createRange();
		var i,start;

//		if(range.parentElement() != ta) return false;

		var range_all = document.body.createTextRange();

		range_all.moveToElementText(ta);
		for(start=0;range_all.compareEndPoints("StartToStart",range) < 0; start++)
			range_all.moveStart("character",1);
		for(i=0;i<=start;i++) {
			if(ta.value.charAt(i) == '\n') start++;
		}
		Debug.trace(0,'yaIEGetSelectionStart returns %d',start);
		return start;
	},
	yaIEGetSelectionEnd: function()
	{
		var ta = this.obj;
		var range = document.selection.createRange();
		var range_all = document.body.createTextRange();

//		if(range.parentElement() != ta) return false;

		var end;

		range_all.moveToElementText(ta);
		for(end = 0;range_all.compareEndPoints("StartToEnd",range) < 0; end++)
			range_all.moveStart("character",1);
		for(i=0;i<=end;i++) {
			if(ta.value.charAt(i) == '\n') end++;
		}
		Debug.trace(0,'yaIEGetSelectionEnd returns %d',end);

		return end;
	},
/* 
  The following codes are adopted from DocumentSelection library of JSVK

  Visit http://debugger.ru/demo/projects/virtualkeyboard/demo_inline.html for Virtual Keyboard

wonghang: updated to trunk 345. 2007-10-27
*/
	GetSelectionStart: function()
	{
		// use if is faster.
		if(GownFullBrowserDetect.current_browser == GownFullBrowserDetect.BROWSER_IE) return this.yaIEGetSelectionStart();
		else return this.obj.selectionStart;
		
		//Debug.trace(0,'GownFullHTMLTextareaAdapter: No GetSelectionStart method supported in this browser.');
		return 0;
/*		var off;
		try {
			this.obj.document.body.setActive();
			off = Math.abs(document.selection.createRange().moveStart("character", -100000000));
			//  test for the TEXTAREA's dumb behavior
			//  calculate node offset
			var r = document.body.createTextRange();
			r.moveToElementText(this.obj);
			var sTest = Math.abs(r.moveStart("character",-100000000));
			Debug.trace(0,'IE GetSelectionStart: off=%d, sTest=%d, fixed off=%d',off,sTest,off-sTest);
			off -= sTest;
		}
		catch (e) {
			try {
				off = this.obj.selectionStart;
			}
			catch (e) {
				off = 0;
			}
		}
		return off;
*/
	},
	GetSelectionEnd: function()
	{
		try {
			return this.yaIEGetSelectionEnd();
		}
		catch(e) {}
		try {
			return this.obj.selectionEnd;
		}
		catch(e) {}
		Debug.trace(0,'GownFullHTMLTextareaAdapter: No GetSelectionEnd method supported in this browser.');
		return 0;

/*		var off;
		try {
			this.obj.document.body.setActive();
			off = Math.abs(document.selection.createRange().moveEnd("character", -100000000));
			// test for the TEXTAREA's dumb behavior
			//  calculate node offset
			var r = document.body.createTextRange();
			r.moveToElementText(this.obj);
			var sTest = Math.abs(r.moveStart("character",-100000000));
			Debug.trace(0,'IE GetSelectionEnd: off=%d, sTest=%d, fixed off=%d',off,sTest,off-sTest);
			off -= sTest;
		}
		catch (e) {
			try {
				off = this.obj.selectionStart;
			}
			catch (e) {
				off = 0;
			}
		}
		return off;
*/
	}
});
